#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void  Transpose1(int arr1[][10], int arr2[][10], int m, int n)
{
	int i = 0;
	int j = 0;
	for (i; i < m; i++)
	{
		for (j=0; j < n; j++)
		{
			arr2[j][i] = arr1[i][j];
		}
	}
}
void Print(int arr[10][10], int m, int n)
{
	int i = 0;
	int j = 0;
	for (i; i < m; i++)
	{
		for (j = 0; j < n; j++)
		{
			printf("%d ", arr[i][j]);
		}
		printf("\n");
	}
	printf("\n");
}
int main()
{
	int arr1[10][10] = { 0 };
	int arr2[10][10] = { 0 };
	int m = 0;
	int n = 0;
	scanf("%d %d", &m, &n);
	int i = 0;
	int j = 0;
	for (i; i < m; i++)
	{
		for (j = 0; j < n; j++)
		{
			scanf("%d", &arr1[i][j]);
		}
	}
	 Transpose1(arr1, arr2 , m,  n);
	 Print(arr2,n ,m);
	 Print(arr2,n ,m);
	 Print(arr2,n ,m);
	 return 0;
}